package com.xhwl.logistics.converter.mapstruct;


import com.alibaba.fastjson.JSONObject;
import com.xhwl.logistics.dto.http.ParkingLotPassageChuangXiangDTO;
import com.xhwl.logistics.dto.http.ParkingLotPassageDeviceChuangXiangDTO;
import com.xhwl.logistics.entity.VehiclePassage;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.NullValueMappingStrategy;

import java.util.List;

/**
 * 将第三方的通道信息转换为中台的通道信息
 */
@Mapper(componentModel = "spring", nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)
public interface VehiclePassageThirdConverter {

    /**
     * 将创享通道信息转换为中台通道信息
     */
    @Mapping(target = "passageName", source = "passageChuangXiangDTO.gateName")
    @Mapping(target = "thirdPassageId", source = "passageChuangXiangDTO.gateId")
    @Mapping(target = "type", expression = "java(chuangXiangtoPassageType(passageChuangXiangDTO.getIostate(),null))")
    @Mapping(target = "remark", expression = "java(chuangXiangtoRemark(passageChuangXiangDTO.getDevData()))")
    VehiclePassage chuangXiangtoVehiclePassage(ParkingLotPassageChuangXiangDTO passageChuangXiangDTO, Integer projectId,Integer parkingLotId,Integer areaId);

    /**
     * 将创享通道的通道类型转换为中台的通道类型
     * 创享通道类型，1：进，2：出
     * 中台通道类型，0：进，1：出
     */
    default Integer chuangXiangtoPassageType(Integer passageType, Integer help){
        switch (passageType){
            case 1:
                return 0;
            case 2:
                return 1;
            default:
                return 99;
        }
    }

    /**
     * 将创享通道信息中的设备转换为String类型
     */
    default String chuangXiangtoRemark(List<ParkingLotPassageDeviceChuangXiangDTO> parkingLotPassageDeviceChuangXiangDTOS){
        return JSONObject.toJSONString(parkingLotPassageDeviceChuangXiangDTOS);
    }
}
